package com.lagou.mr.number_sort;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class NumberSortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        /*
            1. 获取配置文件对象，获取job对象实例
            2. 指定程序jar的本地路径
            3. 指定Mapper/Reducer类
            4. 指定Mapper输出的kv数据类型
            5. 指定最终输出的kv数据类型
            6. 指定job处理的原始数据路径
            7. 指定job输出结果路径
            8. 提交作业
         */
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "NumberSortDriver");

        job.setJarByClass(NumberSortDriver.class);

        job.setMapperClass(NumberSortMapper.class);
        job.setReducerClass(NumberSortReducer.class);

        job.setMapOutputKeyClass(NumberBean.class);
        job.setMapOutputValueClass(NullWritable.class);

        job.setOutputKeyClass(NumberBean.class);
        job.setOutputValueClass(NullWritable.class);

        // 默认1个reducetask
        // 设置reducetask数量为1
        // job.setNumReduceTasks(1);

        FileInputFormat.setInputPaths(job, new Path("/Users/songhao/Desktop/learning/codes/third-stage-first-module/input_files"));

        FileOutputFormat.setOutputPath(job, new Path("/Users/songhao/Desktop/learning/codes/third-stage-first-module/output"));

        boolean flag = job.waitForCompletion(true);

        System.exit(flag ? 0 : 1);
    }
}
